<script setup lang="ts">
import { FormGrid } from '@formily/element-plus';
import { TreeNode } from '@season-designable/core';
import { TextWidget, useTreeNode, usePrefix } from '@season-designable/vue';

const prefix = usePrefix('node-actions');
const node = useTreeNode();
const slots = defineSlots();
// const attrs = useAttrs();

const addCloumn = () => {
  const column = new TreeNode({
    componentName: 'Field',
    props: {
      type: 'void',
      'x-component': 'FormGridColumn',
    },
  });

  node?.append(column);
};

// const columnGap = ref(0);

// onMounted(() => {
//   columnGap.value = (attrs.columnGap as number) || 8;
// });
</script>

<template>
  <div>
    <FormGrid class="form-gird">
      <slot></slot>
    </FormGrid>

    <div :class="prefix">
      <div :class="prefix + '-content'">
        <ElLink :underline="false" :class="prefix + '-item'" @click="addCloumn">
          <span :class="prefix + '-item-text'">
            <IMdiPlaylistPlus></IMdiPlaylistPlus>
            <TextWidget>
              {{ node?.getMessage('addGridColumn') }}
            </TextWidget>
          </span>
        </ElLink>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
@import '../../../styles.scss';

.form-gird {
  grid-template-columns: repeat(3, 1fr);
}

.dn-node-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  overflow: hidden;
  padding-top: 8px;
  padding-bottom: 8px;
  &-content {
    position: relative;
    padding: 0 20px;
    display: flex;
    align-items: center;
    line-height: 1;
    &::before {
      position: absolute;
      content: '';
      display: block;
      height: 0;
      width: 300%;
      top: 50%;
      border-bottom: 1px dashed #{$border-color-split};
      right: 100%;
    }
    &::after {
      position: absolute;
      content: '';
      display: block;
      height: 0;
      width: 300%;
      top: 50%;
      border-bottom: 1px dashed #{$border-color-split};
      left: 100%;
    }
    // a {
    // color: #{$text-color-secondary};
    // &:hover {
    //   color: #{$primary-color};
    // }
    // }
  }

  &-item {
    &-text {
      font-size: 10px;
      display: flex;
      align-items: center;
      line-height: 1;
      .dn-icon {
        margin-right: 6px;
      }
    }
  }
}
</style>
